﻿(function ($) {
    $.fn.dropdownlist = function () {
        var _tree = this;
        var _content = $("<div style=\"position:relative;\"></div>");
        var _selectedText = $("<div class=\"selectedText\">&nbsp;</div>");
        _content.append(_selectedText);
        this.parent().append(_content);
        _content.append(_tree);

        // 设置值
        var _setValue = function () { _tree.hide(); _selectedText.text(_tree.find(":checked").attr("title")); };
        // 展开菜单
        _selectedText.click(function (event) { _tree.toggle(); event.stopPropagation(); $(document.body).one("click", _setValue); });
        //点击tree停止冒泡
        _tree.click(function (event) { event.stopPropagation(); });
        // 点击lable的时候选中值
        _tree.find("label").click(function () { setTimeout(_setValue, 500); });
        _tree.treeview();
        _setValue();
    }
})(jQuery);